include <iostream>

using namespace std;

int main()
{
    string s, s1;
    bool flag = true;

    cout << "Введите скобочную последовательность:" << endl;
    getline(cin, s);
    s1 = "";

    for (char el : s)
    {
        if (el == '(')
        {
            s1 += el;
        }
        if (el == ')')
        {
            if (s1.length() >= 0)
            {
                if (s1[s1.length() - 1] == '(')
                {
                    s1.pop_back();
                }
                else {flag = false;}
            }
        }
        if (el == '{')
        {
            s1 += el;
        }
        if (el == '}')
        {
            if (s1.length() >= 0)
            {
                if (s1[s1.length() - 1] == '{')
                {
                    s1.pop_back();
                }
                else {flag = false;}
            }
        }
        if (el == '[')
        {
            s1 += el;
        }
        if (el == ']')
        {
            if (s1.length() >= 0)
            {
                if (s1[s1.length() - 1] == '[')
                {
                    s1.pop_back();
                }
                else {flag = false;}
            }
        }
        if (el == '<')
        {
            s1 += el;
        }
        if (el == '>')
        {
            if (s1.length() >= 0)
            {
                if (s1[s1.length() - 1] == '<')
                {
                    s1.pop_back();
                }
                else {flag = false;}
            }
        }
    }
    if (s1.length() > 0)
    {
        flag = false;
    }
    if (not flag)
    {
        cout << "False" << endl;
    }
    else
    {
        cout << "True" << endl;
    }

    return 0;
}
